package com.lc.boxuegu.S_sortedArrayToBST;

/**
 * @author zhaiyj
 * @date 2025/6/14 20:01
 */
public class Solution {

    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums, 0 , nums.length);
    }

    private TreeNode dfs(int[] nums, int left, int right){
        if(left == right){
            return null;
        }
        int m = (left + right) >>> 1;
        return new TreeNode(nums[m], dfs(nums, left, m), dfs(nums, m + 1, right));
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


}
